home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1995 / MacHack 1995.toast / Presentations / Presentations ’88 / Feldt's Object Stuff / objectMgr stuff / Object.c < prev    next >
Text File  |  1987-04-11  |  3KB  |  154 lines

  1. /*                          Small Systems Guild                                */
  2. /*                               PO box 2751                                    */
  3. /*                             3105 Sunnywood                                    */
  4. /*                        Ann Arbor, Michigan 48103                            */
  5. /*                             (313) 996-4238                                    */
  6.  
  7. /*                   copyright © 1987 Small Systems Guild                         */
  8.  
  9. /*                      source code compilable using                            */
  10. /*                       Lightspeed C compiler 2.01                            */
  11.  
  12. #include    "objectMgr.h"
  13.  
  14. Handle Object(sel,arg)
  15. USHORT        sel;
  16. ULONG        arg;
  17. {
  18.     switch(sel) {
  19.         case NEW:                        /* MUST be unique for each subclass    */
  20.             return(new_object());
  21.             break;
  22.         case SELF:
  23.             return(self_object(arg));
  24.             break;
  25.         case CLASS:
  26.             return(class_object(arg));
  27.             break;
  28.         case SIZE:
  29.             return(size_object(arg));
  30.             break;
  31.         case ASK_STATUS:
  32.             return(ask_object(arg));
  33.             break;
  34.         case SET_STATUS:
  35.             return(set_object(arg));
  36.             break;
  37.         case VALID:
  38.             return(valid_object(arg));
  39.             break;
  40.         case FREE:
  41.             return(free_object(arg));
  42.             break;
  43.         default:
  44.             return(NULL);
  45.     }
  46. }
  47.  
  48. Handle new_object()
  49. {
  50.     Handle            objHndl;
  51.     ULONG            size;
  52.     
  53.     size = (ULONG)sizeof(object);
  54.     objHndl = NewHandle(size);
  55.     if (!ValidHandle(objHndl))
  56.         return(NULL);
  57.     (**((object **)objHndl)).isa = OBJECT;
  58.     (**((object **)objHndl)).size = size;
  59.     (**((object **)objHndl)).status = INACTIVE;
  60.     (**((object **)objHndl)).sync = OBJ_SYNC;
  61.     (**((object **)objHndl)).id = objHndl;
  62.     return(objHndl);
  63. }
  64.     
  65. Handle self_object(objHndl)
  66. Handle        objHndl;
  67. {
  68.     
  69.     if (!ValidHandle(objHndl))
  70.         return(NULL);
  71.  
  72.     return(objHndl);
  73. }
  74.     
  75. Handle class_object(objHndl)
  76. Handle        objHndl;
  77. {
  78.     
  79.     if (!ValidHandle(objHndl))
  80.         return(NULL);
  81.  
  82.     return((Handle)(**((object **)objHndl)).isa);
  83. }
  84.  
  85. Handle size_object(objHndl)
  86. Handle        objHndl;
  87. {
  88.     
  89.     if (!ValidHandle(objHndl))
  90.         return(NULL);
  91.  
  92.     return((Handle)((**((object **)objHndl)).size));
  93. }
  94.     
  95. Handle ask_object(objHndl)
  96. Handle        objHndl;
  97. {
  98.     
  99.     if (!ValidHandle(objHndl))
  100.         return(NULL);
  101.  
  102.     return((Handle)((**((object **)objHndl)).status));
  103. }
  104.     
  105. Handle set_object(argPtr)
  106. Ptr        argPtr;
  107. {
  108.     Handle        objHndl;
  109.     ULONG        objData;
  110.         
  111.     if (!ValidPointer(argPtr))
  112.         return(NULL);
  113.  
  114.     objHndl = ((msgArgs *)argPtr)->objHndl;
  115.     objData = ((msgArgs *)argPtr)->objDat1;
  116.  
  117.     if (!ValidHandle(objHndl))
  118.         return(NULL);
  119.  
  120.     if (objData < INACTIVE || objData > DAMAGED)
  121.         return(NULL);
  122.     
  123.     (**((object **)objHndl)).status = (USHORT)objData;
  124.     return(objHndl);
  125. }
  126.     
  127. Handle valid_object(objHndl)
  128. Handle        objHndl;
  129. {
  130.     
  131.     if (!ValidHandle(objHndl))
  132.         return(NULL);
  133.  
  134.     if (((**((object **)objHndl)).sync == OBJ_SYNC))
  135.         return(objHndl);
  136.     else
  137.         return(NULL);
  138. }
  139.     
  140. Handle free_object(objHndl)
  141. Handle        objHndl;
  142. {
  143.     
  144.     if (!ValidHandle(objHndl))
  145.         return(objHndl);
  146.  
  147.     if ((**((object **)objHndl)).status == ACTIVE)
  148.         return(objHndl);
  149.  
  150.     DisposHandle(objHndl);
  151.     return(NULL);
  152. }
  153.     
  154.